#include <bits/stdc++.h>

using namespace std;
#define fi(i, init, n) for (int i = init; i < n; i++)   // i为循环变量，a为初始值，n为界限值，递增
#define rfi(i, init, n) for (int i = init; i > n; i--)  // i为循环变量， a为初始值，n为界限值，递减。
#define vi vector<int>
#define mii unordered_map<int, int>
#define between(a, l, h) (a >= l && a <= h)
const int INF = 0x7fffffff;  // 无穷大
typedef long long ll;

class Solution {
public:
    vector<int> queryResults(int limit, vector<vector<int>>& queries) {
        mii color_cnt;
        mii ball_color;
        vi ans;
        int num = 0;
        for (auto& q : queries) {
            // ball has colored
            if (ball_color.find(q[0]) != ball_color.end()) {
                int oldColor = ball_color[q[0]];
                if (color_cnt[oldColor] == 1) {
                    num--;
                }
                color_cnt[oldColor]--;
            }
            ball_color[q[0]] = q[1];
            if (color_cnt[q[1]] == 0) {
                num++;
            }
            color_cnt[q[1]]++;
            ans.push_back(num);
        }
        return ans;
    }
};

// int main(int argc, const char** argv) {
//     Solution solution = Solution();
//     vector<int> in = {2, 1, 1};
//     auto res = solution.solution(in);
//     cout << res << endl;
//     return 0;
// }